<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="https://www.thymeleaf.org">
<head>
    <title>订单管理</title>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" media="all" href="/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css">
    <script type="text/javascript" src="/js/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/layui/layui.js"></script>
</head>
<script>
    function CheckValues(ID) {
        $("#CheckID").val(ID);
    }
    function FinishValues(ID) {
        $("#FinishID").val(ID);
    }
    function DeleteValues(ID) {
        $("#DeleteID").val(ID);
    }
    function SelectOrderProduct(ID){
        data = {
            id: ID
        }
        $.ajax({
            url: "findOrderProduct",
            type: "Post",
            data: data,
            dataType: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function FindOrderState() {
        var state = $("#orderState").val();
        data = {
            state: state
        }
        $.ajax({
            url: "findOrderByState",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function SearchAOrder() {
        var account = $("#searchAOrder").val();
        data = {
            account: account
        }
        $.ajax({
            url: "findOrderByAccount",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function SearchROrder() {
        var room = $("#searchROrder").val();
        data = {
            room: room
        }
        $.ajax({
            url: "findOrderByRoom",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function CheckOrder() {
        var orderID = $("#CheckID").val();
        data = {
            orderID: orderID
        }
        $.ajax({
            url: "checkOrderByID",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function DeleteOrder() {
        var orderID = $("#DeleteID").val();
        data = {
            orderID: orderID
        }
        $.ajax({
            url: "order/deleteOrder",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
    function FinishOrder() {
        var orderID = $("#FinishID").val();
        data = {
            orderID: orderID
        }
        $.ajax({
            url: "order/finishOrder",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
</script>
<body>
<div class="container mt-3" id="roomInformation">
    <h2>订单管理界面</h2>
    <br>
    <ul class="nav nav-pills" role="tablist">

        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="searchAOrder" placeholder="搜索账号"/>
            </a>
        </li>
        <li>
            <button type="submit" class="btn btn-default" onclick="SearchAOrder()">搜索</button>
        </li>
        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="searchROrder" placeholder="搜索房间号"/>
            </a>
        </li>
        <li>
            <button type="submit" class="btn btn-default" onclick="SearchROrder()">搜索</button>
        </li>

        <div class="producttype">
            <select id="orderState" onchange="FindOrderState()" type="button" class="btn btn-light btn-sm">
                <option>按照订单状态筛选</option>
                <option value="7">全部</option>
                <option value="0">待完成</option>
                <option value="1">已完成</option>
            </select>
        </div>

    </ul>
    <div class="tab-content">
        <div id="home" class="container tab-pane active"><br>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>订单号</th>
                    <th>账号</th>
                    <th>房间名</th>
                    <th>下单时间</th>
                    <th>完成时间</th>
                    <th>订单状态</th>
                    <th>金额</th>
                    <th style="width: 300px">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="order:${orders}">
                    <td th:text="${order.orderID}"></td>
                    <td th:text="${order.account}"></td>
                    <td th:text="${order.room}"></td>
                    <td th:text="${order.submitTime}"></td>
                    <td th:text="${order.finishTime}"></td>
                    <td th:if="${order.state}==0">待完成</td>
                    <td th:if="${order.state}==1">已完成</td>
                    <td th:text="${order.cost}"></td>
                    <td>
                        <button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#select" th:onclick="|javascript:SelectOrderProduct('${order.orderID}')|">查看订单</button>
                        <button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#fire" th:onclick="|javascript:DeleteValues('${order.orderID}')|">删除订单</button>
                        <button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#modify" th:onclick="|javascript:FinishValues('${order.orderID}')|" th:if="${order.state}==0">完成订单</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal Fire" id="fire">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">删除订单</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">订单号</td><td><input readonly="readonly" id="DeleteID" name="DeleteID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">是否删除该订单？</td><td style="height:32px;width:300px;font-size:22px">永久删除该订单（真的很久）</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="DeleteOrder()">是</button>
            </div>

        </div>
    </div>
</div>

<div class="modal alter" id="modify">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h4 class="modal-title">完成订单</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">订单号</td><td><input id="FinishID" name="FinishID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">是否完成该订单？</td><td style="height:32px;width:300px;font-size:22px">他真的给钱了吗？</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="FinishOrder()">确定</button>
            </div>

        </div>
    </div>
</div>

</body>
</html>